home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap04 / AutomaticDoor.java < prev    next >
Text File  |  1996-09-20  |  1KB  |  45 lines

  1. //
  2. // toggle the light state.
  3. // control the automatic door.
  4. // 
  5.  
  6. import vrml.*;
  7. import vrml.node.*;
  8. import vrml.field.*;
  9.  
  10. public class AutomaticDoor extends Script{
  11.     SFBool turnOnLight;
  12.     SFTime openDoor;
  13.     SFTime closeDoor;
  14.     
  15.     // light state.
  16.     boolean onOff = false;
  17.  
  18.     public void initialize(){
  19.         // get the reference of the event out 'turnOnLight'.
  20.         turnOnLight = (SFBool)getEventOut("turnOnLight");
  21.         // get the reference of the event out 'openDoor'.
  22.         openDoor = (SFTime)getEventOut("openDoor");
  23.         // get the reference of the event out 'closeDoor'.
  24.         closeDoor = (SFTime)getEventOut("closeDoor");
  25.     }
  26.  
  27.     public void processEvent(Event e){
  28.         if(e.getName().equals("touched") == true){
  29.             // toggle the light state.
  30.             onOff = !onOff;
  31.             // send the event.
  32.             turnOnLight.setValue(onOff);
  33.         }else if(e.getName().equals("enterArea") == true){
  34.             if(true == onOff){
  35.                 // open the door if the light is on.
  36.                 openDoor.setValue(((ConstSFTime)e.getValue()).getValue());
  37.             }
  38.         }else if(e.getName().equals("exitArea") == true){
  39.             // close the door.
  40.             closeDoor.setValue(((ConstSFTime)e.getValue()).getValue());
  41.         }
  42.     }
  43. }
  44.  
  45.